package com.lili.math;

/**
 * @Auther: 李 力
 * @Date: 2024/7/30
 * @Description: 整数的各位积和之差
 * @version: 1.0
 */
public class LeetCode1281 {

    /*
     * 时间复杂度:O(n)
     * 空间复杂度:O(1)
     *
     */
    public static int subtractProductAndSum(int n) {
        if (n == 0) {
            return 0;
        }
        int chenji = 1;
        int leijia = 0;
        while (n != 0) {
            int num = n % 10;
            chenji = chenji * num;
            leijia = leijia + num;
            n = n / 10;
        }
        return chenji - leijia;
    }
}
